﻿<%@ Page Language="C#" MasterPageFile="~/user.master" AutoEventWireup="true" Inherits="MediaMonitor.Users.Orders"
    Theme="default" Title="Orders" CodeBehind="orders.aspx.cs" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script src="../rad-scripts/rad.js" type="text/javascript"></script>
        <script type="text/javascript">
               
                function getOuterHTML(object) {
                    var element;
                    if (!object) return null;
                    element = document.createElement("div");
                    element.appendChild(object.cloneNode(true));
                    return element.innerHTML;
                }

                function PrintRadGrid() {
                    var previewWnd = window.open('about:blank', '', '', false);
                    var sh = '<%= ClientScript.GetWebResourceUrl(radGrid.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",radGrid.Skin)) %>';
                    var styleStr = "<html><head><title>Media Monitor - Invoice</title><link href = '" + sh + "' rel='stylesheet' type='text/css'></link></head>";
                    var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= radGrid.ClientID %>').get_element()) + "</body></html>";
                    previewWnd.document.open();
                    previewWnd.document.write(htmlcontent);
                    previewWnd.document.close();
                    previewWnd.print();
                    previewWnd.close();
                }


                function requestStart(sender, args) {
                    if (args.get_eventTarget().indexOf("DownloadPDF") > 0)
                        args.set_enableAjax(false);
                }
        </script>
    </telerik:RadCodeBlock>
    
   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server">
    
    <iframe id="frmDownload"  width="1 " height="1" frameborder="0"></iframe>
         <script type="text/javascript">
             function GetDownload(odid, type) {
                 var iframe = document.getElementById("frmDownload");
                 iframe.src = "../sitefiles/download.aspx?odid=" + odid + "&type=" + type;
             }
         </script>
     <telerik:RadAjaxPanel ID="radPanel" runat="server" RestoreOriginalRenderDelegate="false" Width="90%">
    <%--<asp:UpdatePanel runat="server">
  <ContentTemplate>
 --%>

        <div style="float: right; text-align: right; padding-bottom:5px;">
         
            <a href="javascript:void();" onclick="PrintRadGrid(); return false;"><b style="color: #336699;">
                [ Print ]</b></a>
        </div>

        <telerik:RadGrid ID="radGrid" runat="server" AllowFilteringByColumn="False" AllowPaging="True"
            AllowSorting="True" GridLines="None" Skin="Hay" OnNeedDataSource="radGrid_NeedDataSource"
            AutoGenerateColumns="false" GroupingSettings-CaseSensitive="false"  OnItemCommand="radGrid_ItemCommand" OnItemCreated="radGrid_ItemCreated"
            PageSize="20"> 
            
            <MasterTableView DataKeyNames="OrderID" ShowFooter="true">
                 
                <Columns>
                   
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="OrderID" HeaderText="Order #" /> 
                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="OrderDate"
                        HeaderText="Purchase Date" HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" />
                    <telerik:GridBoundColumn AutoPostBackOnFilter="false" DataField="FullName"  HeaderText="Cusotmer" />
                    <telerik:GridHyperLinkColumn Text="Invoice" DataNavigateUrlFields="OrderID" DataNavigateUrlFormatString="invoice.aspx?oid={0}" />
                    

                      <telerik:GridButtonColumn CommandName="DownloadAll" 
	FilterControlAltText="Download All" Text="Download All" 
	UniqueName="selectButton">
</telerik:GridButtonColumn>

                    
                    <telerik:GridBoundColumn DataField="OrderTotal" HeaderText="Total Amount" ItemStyle-HorizontalAlign="Right"
                        DataFormatString="{0:C2}" Aggregate="Sum" FooterAggregateFormatString="Grand Total: {0:c2}"
                        FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true" />
                    
                </Columns>
                <DetailTables >
                    
                    <telerik:GridTableView AutoGenerateColumns="false"  Caption="" AllowSorting="true" PageSize="20" DataSourceID="sqlOrdItems" AllowFilteringByColumn="false" ShowFooter="true" ItemStyle-VerticalAlign="Top" GroupsDefaultExpanded="true">
                        
                        <ParentTableRelation>
                            <telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID" />
                        </ParentTableRelation>
                        <ItemStyle />
                        <AlternatingItemStyle />
                        <Columns>
                            <telerik:GridTemplateColumn ItemStyle-Width="20px" UniqueName="MediaType">
                                <ItemTemplate>
                                    <img src='../images/media/<%#Eval("MediaTypeName")%>.png' alt='<%#Eval("MediaTypeName")%>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProductCode" HeaderText="Product Code"
                                ItemStyle-Width="70" />
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProductName"
                                HeaderText="Product" ItemStyle-Width="150" />

                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProdVersionCode"
                                HeaderText="Version Code" ItemStyle-Width="70" />
                            <telerik:GridBoundColumn AutoPostBackOnFilter="true" DataField="ProdVersionName"
                                HeaderText="Version" ItemStyle-Width="150" /> 
                            
                            <telerik:GridTemplateColumn HeaderText="Full Video" ItemStyle-Width="150">
                                <ItemTemplate>
                                    <!--view for TV-->
                                    <a href="javascript:void(0);" onclick="PopupCenter('../sitefiles/video.aspx?pvid=<%#Eval("ProdVersionID")%>&t=f&odid=<%#Eval("OrderDetailID")%>', '_blank', 350, 280); "  style='Display: <%#Eval("MediaTypeCode").ToString() == "1" ? "inline" : "none"  %>'>
                                        <span style='color: <%#Utility.CheckVideoAvailability(Eval("FullVideoFile").ToString())==true ? "green" : "red"%>;'> View </span>
                                    </a>
                                    <!--view for Radio-->
                                    <a href="javascript:void(0);" onclick="PopupCenter('../sitefiles/radio.aspx?pvid=<%#Eval("ProdVersionID")%>&t=f&odid=<%#Eval("OrderDetailID")%>', '_blank', 350, 280); "
                                        style='display: <%# Eval("MediaTypeCode").ToString() == "3"? "inline" : "none"  %>'>
                                        <span style='color: <%#Utility.CheckRadioAvailability(Eval("FullVideoFile").ToString())==true ? "green" : "red"%>;'>
                                            View </span></a>
                                    <!--view for Cable-->
                                    <a href="javascript:void(0);" onclick="PopupCenter('../sitefiles/cable.aspx?pvid=<%#Eval("ProdVersionID")%>&t=f&odid=<%#Eval("OrderDetailID")%>', '_blank', 350, 280); "
                                        style='display: <%#Eval("MediaTypeCode").ToString() == "5" ? "inline" : "none"  %>'>
                                        <span style='color: <%#Utility.CheckCableAvailability(Eval("FullVideoFile").ToString())==true ? "green" : "red"%>;'>
                                            View </span></a>
                                    <!--view for PRESS--> 
                                    <a href="javascript:void(0);" onclick="PopupCenterWithScroll('../sitefiles/press.aspx?pvid=<%#Eval("ProdVersionID")%>&t=s&file=<%#Eval("PressFile")%>', '_blank', 750, 700); ">
                                        <span style='color: <%# Utility.ToStr(Eval("PressFile"))!="" ? "green" : "red"%>;'>
                                            <%#Utility.GetFormattedBool(Utility.ToInt(Eval("MediaTypeCode")) == 6 &&  Utility.CheckPressAvailability(Utility.ToStr(Eval("PressFile")).ToString()), "Preview", "")%>
                                        </span></a>
                                    <!--view for OutDoor-->
                                    <a href="javascript:void(0);" onclick="PopupCenterWithScroll('../sitefiles/outdoor.aspx?pvid=<%#Eval("ProdVersionID")%>&t=s&file=<%#Eval("OutDoorFile")%>', '_blank', 750, 700); ">
                                        <span style='color: <%# Utility.ToStr(Eval("OutDoorFile"))!="" ? "green" : "red"%>;'>
                                            <%#Utility.GetFormattedBool(Utility.ToInt(Eval("MediaTypeCode")) == 7 &&  Utility.CheckOutDoorAvailability(Utility.ToStr(Eval("OutDoorFile")).ToString()), "Preview", "")%>
                                        </span></a>

                                         <!--view for INTERNET--> 
                                    <a href="javascript:void(0);" onclick="PopupCenterWithScroll('../sitefiles/internet.aspx?pvid=<%#Eval("ProdVersionID")%>&t=s&file=<%#Eval("InternetFile")%>', '_blank', 750, 700); ">
                                        <span style='color: <%# Utility.ToStr(Eval("InternetFile"))!="" ? "green" : "red"%>;'>
                                            <%#Utility.GetFormattedBool(Utility.ToInt(Eval("MediaTypeCode")) == 9 && Utility.CheckInternetAvailability(Utility.ToStr(Eval("InternetFile")).ToString(), Utility.ToStr(Eval("OrderDate"))), "Preview", "")%>
                                        </span></a>


                                        -
                                    <!--download for TV--> 
                                          
                                        <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "tv"); return false;' href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "1" ? "inline" : "none"  %>'>Download</a>
                                    <!--download for Radio-->
                                    <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "radio"); return false;'  href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "3" ? "inline" : "none"  %>'>
                                        Download</a>
                                    <!--download for Cable-->
                                    <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "cable"); return false;' href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "5" ? "inline" : "none"  %>'>
                                        Download</a>
                                    <!--download for PRESS-->
                                        <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "press"); return false;' href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "6" ? "inline" : "none"  %>'>Download</a> 

                                        <!--download for OutDoor-->
                                        <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "outdoor"); return false;' href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "7" ? "inline" : "none"  %>'>Download</a> 

                                         <!--download for INTERNET-->
                                        <a onclick='javascript:GetDownload(<%#Eval("OrderDetailID")%>, "internet"); return false;' href="javascript:void(0);" style='display: <%#Eval("MediaTypeCode").ToString() == "9" ? "inline" : "none"  %>'>Download</a> 
                                        
                                </ItemTemplate>


                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField ="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:C2}" Aggregate="Sum" FooterAggregateFormatString="Order Total: {0:c2}" FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true" /> 
                           
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
            <ClientSettings>
                <Scrolling AllowScroll="false" />
                <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
            </ClientSettings>
            <FilterMenu OnClientShowing="MenuShowing" />
        </telerik:RadGrid>
        <asp:LinkButton ID="lnkHidden" runat="server" Text=""></asp:LinkButton>

    </telerik:RadAjaxPanel>
   <%--</ContentTemplate>
     </asp:UpdatePanel>--%>

    <asp:SqlDataSource ID="sqlOrdItems" runat="server" ConnectionString="<%$ ConnectionStrings:DBAdex %>"
        SelectCommand="SELECT * FROM vOrderDetail WHERE OrderID = @OrderID">
        <SelectParameters>
            <asp:Parameter Name="OrderID" DefaultValue="0" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
